/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.structure;

import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberBeaconData;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspDeserializer;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspSerializer;

/**
 * Class to implement the Ember Structure <b>EmberBeaconIterator</b>.
 * <p>
 * Defines an iterator that is used to loop over cached beacons. Do not write to fields denoted as
 * Private.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class EmberBeaconIterator {

    /**
     * The channel of the received beacon.
     * <p>
     * EZSP type is <i>EmberBeaconData</i> - Java type is {@link EmberBeaconData}
     */
    private EmberBeaconData beacon;

    /**
     * (Private) The index of the retrieved beacon.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int index;

    /**
     * Default Constructor
     */
    public EmberBeaconIterator() {
    }

    public EmberBeaconIterator(EzspDeserializer deserializer) {
        deserialize(deserializer);
    }

    /**
     * The channel of the received beacon.
     * <p>
     * EZSP type is <i>EmberBeaconData</i> - Java type is {@link EmberBeaconData}
     *
     * @return the current beacon as {@link EmberBeaconData}
     */
    public EmberBeaconData getBeacon() {
        return beacon;
    }

    /**
     * The channel of the received beacon.
     *
     * @param beacon the beacon to set as {@link EmberBeaconData}
     */
    public void setBeacon(EmberBeaconData beacon) {
        this.beacon = beacon;
    }

    /**
     * (Private) The index of the retrieved beacon.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current index as {@link int}
     */
    public int getIndex() {
        return index;
    }

    /**
     * (Private) The index of the retrieved beacon.
     *
     * @param index the index to set as {@link int}
     */
    public void setIndex(int index) {
        this.index = index;
    }

    /**
     * Serialise the contents of the EZSP structure.
     *
     * @param serializer the {@link EzspSerializer} used to serialize
     */
    public int[] serialize(EzspSerializer serializer) {
        // Serialize the fields
        serializer.serializeEmberBeaconData(beacon);
        serializer.serializeUInt8(index);
        return serializer.getPayload();
    }

    /**
     * Deserialise the contents of the EZSP structure.
     *
     * @param deserializer the {@link EzspDeserializer} used to deserialize
     */
    public void deserialize(EzspDeserializer deserializer) {
        // Deserialize the fields
        beacon = deserializer.deserializeEmberBeaconData();
        index = deserializer.deserializeUInt8();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(72);
        builder.append("EmberBeaconIterator [beacon=");
        builder.append(beacon);
        builder.append(", index=");
        builder.append(index);
        builder.append(']');
        return builder.toString();
    }
}
